<template>
  <view class="scene">
    <view class="scene-des-wrap">
      <view
        class="scene-des-info"
        v-for="(item, index) in scene"
        :key="index"
        @tap="jumpHandler(item)"
      >
        <text :user-select="true">{{ item.scene }}</text>
      </view>
    </view>
    <u-modal
      :show="show"
      @confirm="confirmHandler"
      title="触发条件"
      width="500rpx"
      :content="condition"
    ></u-modal>
  </view>
</template>

<script>
export default {
  data() {
    return {
      sceneList: [
        {
          addressId: 1,
          sceneName: "丰收广场",
          children: [
            {
              id: 1,
              pid: 0,
              scene: "藏书院",
              condition: "来了直接给一张线索卡。每名玩具做多探索2次",
            },
            {
              id: 2,
              pid: 0,
              scene: "督查院",
              condition: "来了直接给一张线索卡。每名玩具做多探索2次",
            },
            {
              id: 3,
              pid: 0,
              scene: "御史台",
              condition: "来了直接给一张线索卡。每名玩具做多探索2次",
            },
          ],
        },
        {
          addressId: 2,
          sceneName: "望仙阁",
          children: [
            {
              id: 4,
              pid: 0,
              scene: "民宅",
              condition: "",
              children: [
                {
                  id: 5,
                  pid: 4,
                  scene: "甲民宅",
                  condition:
                    "甲大过于播弱，只要有人来打他，他就给东西。（可参考台词）青天门人：这位官谷，我加入青天门只是为了求个温饱，你可千万别杀我啊，我什么东西都给你。",
                },
                {
                  id: 6,
                  pid: 4,
                  scene: "乙民宅",
                  condition: "",
                },
                {
                  id: 7,
                  pid: 4,
                  scene: "丙民宅",
                  condition:
                    "青天门人：其实我并不喜欢打打系系，加入青天门也只是为了生存嘛。只要这为少一千两银子，那我便把知道的事恃和物品都给你，如何？（给钱就个用打）",
                },
                {
                  id: 8,
                  pid: 4,
                  scene: "丁民宅",
                  condition: "",
                },
                {
                  id: 9,
                  pid: 4,
                  scene: "戊民宅",
                  condition: "",
                },
                {
                  id: 10,
                  pid: 4,
                  scene: "已民宅",
                  condition:
                    "青天门人：少使製要消息很简单，我老母如今重病在身，只要你给我两个金店药，我便把清息香诉号你，如何？（给了东西，直接始线素和掉落物品）",
                },
                {
                  id: 11,
                  pid: 4,
                  scene: "庚民宅",
                  condition:
                    "青天门人：哎，少侠啊。你想要知道一些消息我可以告诉你，但我心爱的女子如今奄奄一息，继续天山雪莲，只要你给我，我便把消息告诉于你，如何？（给了东西直接给线索和掉落物品）",
                },
              ],
            },
            {
              id: 12,
              pid: 0,
              scene: "王府",
              condition: "",
              children: [
                {
                  id: 14,
                  pid: 12,
                  scene: "山虎陆公明",
                  condition:
                    "需要雷形钥匙开门。(若为伍云涛前来，会对伍云诗说，此处有他在，速去别处调查）（若为任北游前来，可以对陆公明进行攻击，击败后触发伍云涛剧情）",
                },
              ],
            },
            {
              id: 13,
              pid: 0,
              scene: "钦天阁",
              condition: "",
              children: [
                {
                  id: 15,
                  pid: 13,
                  scene: "钦天兵",
                  condition: "",
                },
              ],
            },
          ],
        },
        {
          addressId: 3,
          sceneName: "古驿站",
          children: [
            {
              id: 16,
              pid: 0,
              scene: "李府",
              condition: "",
              children: [
                {
                  id: 19,
                  pid: 16,
                  scene: "退役御林军兵卒",
                  condition: "",
                },
              ],
            },
            {
              id: 17,
              pid: 0,
              scene: "湖心后院",
              condition: "",
              children: [
                {
                  id: 20,
                  pid: 17,
                  scene: "锦衣卫",
                  condition: "",
                },
              ],
            },
            {
              id: 18,
              pid: 0,
              scene: "静养殿",
              condition: "",
              children: [
                {
                  id: 21,
                  pid: 18,
                  scene: "白衣文士",
                  condition:
                    "既然此处乃是静养院那便光须这般泉躁，若是少侠想要夫的东西，说来也简单，只要接下老大这半阙诗句，我便把东西赠丁你，如何？（对上了诗句直接给) 上半阙：千山鸟飞绝，万径人踪灭。下半阙：孤帆蓑笠翁，独钓寒江雪。",
                },
              ],
            },
          ],
        },
      ],
      scene: [],
      addressId: 0,
      pid: 0,
      condition: "",
      show: false,
    };
  },
  onLoad(options) {
    if (options) {
      this.addressId = options.id;
      this.pid = options.pid;
    }
  },
  mounted() {
    this.init();
  },
  methods: {
    confirmHandler() {
      this.show = false;
    },
    jumpHandler(val) {
      if (val.children === undefined) {
        this.condition = val.condition ? val.condition : "暂无特殊条件";
        this.show = true;
      } else {
        this.$Router.push({
          name: "scene",
          query: {
            pid: val.id,
          },
        });
        // this.scene = val.children;
      }
    },
    init() {
      if (this.addressId) {
        this.sceneList.forEach((item) => {
          if (item.addressId == this.addressId) {
            this.scene = item.children;
          }
        });
      }
      if (this.pid) {
        this.getScene(this.sceneList);
      }
    },
    //递归回去场景数据
    getScene(list) {
      list.forEach((item) => {
        if (this.pid == item.pid) {
          this.scene.push({
            id: item.id,
            pid: item.pid,
            scene: item.scene,
            condition: item.condition,
            children: item.children,
          });
        }
        if (item.children) {
          this.getScene(item.children);
        }
      });
    },
  },
};
</script>

<style>
page {
  background-color: #2f3542;
}
</style>
<style lang="scss" scoped>
.scene {
  margin-top: 40rpx;
  .scene-des-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    .scene-des-info {
      display: flex;
      justify-content: center;
      background: #ffffff;
      font-size: 36rpx;
      color: #333333;
      padding: 34rpx 30rpx;
      margin: 56rpx 0;
      width: 80%;
      border-radius: 10rpx;
      font-weight: 600;
    }
  }
}
</style>
